package offer.nowcoder.array;

/**
 * @author DengYuan2
 * @create 2021-03-14 19:39
 */
public class NC7 {
    public static void main(String[] args) {
        NC7 n = new NC7();
        int[] arr = {1,4,2,6};
        int res = n.maxProfit(arr);
        System.out.println(res);
    }

    public int maxProfit (int[] prices) {
        int min=prices[0];
        int max=0;
        for (int i = 1; i < prices.length; i++) {
            if (prices[i]<min){
                min=prices[i];
            }else {
                max=Math.max(max,prices[i]-min);
            }

        }
        return max;
    }
}
